// pages/scene/scene.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searValue: '',
    serchType: {
      text: 'map',
      content: '',
      placehould: '查找地点、公交、地铁'
    },
    
    pull_style:'up',//上拉 or 下拉
    dropMenuList: [{
        id: 1,
        className: '附近',
        classList: [{
          id: 1,
          itemName: '默认'
        }, {
          id: 2,
          itemName: '500米'
        }, {
          id: 3,
          itemName: '1000米'
        }]
      },
      {
        id: 2,
        className: '分类',
        classList: [{
          id: 1,
          itemName: '全部景点'
        }, {
          id: 2,
          itemName: '风景区'
        }, {
          id: 3,
          itemName: '文博院馆'
        }, {
          id: 4,
          itemName: '寺庙观赏'
        }, {
          id: 5,
          itemName: '旅游度假区'
        }]
      }, {
        id: 3,
        className: '排序',
        classList: [{
          id: 1,
          itemName: '智能排序'
        }, {
          id: 2,
          itemName: '距离优先'
        }, {
          id: 3,
          itemName: '人气优先'
        }, {
          id: 4,
          itemName: '好评优先'
        }]
      }
    ],
    dropMenuNum: 0,
    subMenuHighLight: [],
    selected: [],

    pageIndex: 1,

    isHiddenMes1: true,

    list: [{
      id: 1,
      storeName: '清源山',
      per_consumption: '18.00',
      pingfen: 4.9,
      juli: '300m',
      imgUrl: '../../images/big_avatar.png',
      shops_num: 50
    }],
    allPages:0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    if (this.data.list.length > 0) {
      that.setData({
        isHiddenMes1: false
      })
    }

    this.getListData();

    this.initDropDown();
  },
  /**
   * 初始化下拉框 
   */
  initDropDown: function() {
    var list = this.data.dropMenuList;

    var ary_outer = [];
    var ary_select = [];
    for (var i = 0; i < list.length; i++) {

      var ary_inner = [];
      for (var j = 0; j < list[i].classList.length; j++) {
        var obj;

        obj = '';
        if (j == 0) {
          obj = 'highlight';
        }

        ary_inner.push(obj);
      }

      ary_outer.push(ary_inner);

      var str = i + '-0';
      ary_select.push(str);

    }

    this.setData({
      dropMenuNum: list.length,
      subMenuHighLight: ary_outer,
      selected: ary_select
    })
  },
  /**
   * 获取游，列表
   */
  getListData: function() {
    var that = this;
    app.apiPost(app.apiList.scenic_list, {
      content: {
        pageNum: that.data.pageIndex,
        pageSize:20
      }
    }, function (res) {
      console.log('景点列表',res);
      var list = res.content.list;

      if (that.data.pull_style=='up'){

        that.setData({
          allPages: res.content.pages,
          list: list
        })
      } else if (that.data.pull_style == 'down'){

        var tempArray = that.data.list;
        tempArray = tempArray.concat(list);
        that.setData({
          allPages: res.content.pages,
          list: tempArray
        })
      }

      if (that.data.list.length > 0) {
        that.setData({
          isHiddenMes1: false
        })
      }
    })
  },
  /**
   * searchview-子组件传值
   */
  onGetValue: function() {
    wx.navigateTo({
      url: '../nearsearch/nearsearch',
    })
  },
  /**
   * 搜索输入框回调
   */
  searchValue: function(e) {
    console.log(e);

    var text = e.detail;
  },
  /**
   * 下拉框回调
   */
  selectIndex: function(e) {
    console.log('选中的索引值', e.detail);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  orderDetail: function(e) {
    console.log(e, e.currentTarget.dataset.index, "商圈详情");
    wx.navigateTo({
      url: '../scenedetail/scenedetail?id=' + e.currentTarget.dataset.id
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showNavigationBarLoading();
    var that = this;
    that.setData({
      pageIndex: 1, // 每次触发下拉事件page=0
      pull_style: 'down'
    })
    //发起请求
    that.getListData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    app.loading();
    that.setData({
      // 页数+1
      pageIndex: that.data.pageIndex + 1,
      pull_style:'up'
    })
    // 上拉获取更多数据
    that.getListData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})